package com.cskaoyan.utils;

import com.cskaoyan.bean.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * @Author tangjian
 * @Date 2021/10/23 16:38
 * @description
 */
public class ShiroGetSubjectMessageUtil {

    public static Integer getUserID() {
        User user = null;
        try {
            Subject subject = SecurityUtils.getSubject();
            user = (User) subject.getPrincipal();
        }catch (NullPointerException e){
            //System.out.println("用户没登录");
            return null;
        }

        return user.getId();
    }

    public static User getUser(){
        User user = null;
        try {
            Subject subject = SecurityUtils.getSubject();
            user = (User) subject.getPrincipal();
        }catch (NullPointerException e){
            //System.out.println("用户没登录");
            return null;
        }

        return user;
    }
}
